package com.rong.shop.controller;

import com.rong.shop.pojo.Product;
import com.rong.shop.service.IProductService;
import com.rong.shop.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/product")
public class ProductController extends BaseController{

    @Autowired
    private IProductService productService;

    @RequestMapping("/findHot")
    @ResponseBody
    public JsonResult<List<Product>> findHot(){

        List<Product> hots = productService.findHot();
        return new JsonResult<List<Product>>(OK, hots);
    }


    @RequestMapping("/findById/{id}")
    @ResponseBody
    public JsonResult<Product> findById(@PathVariable("id") Integer id){
        Product product = productService.findById(id);
        return new JsonResult<>(OK, product);
    }

}
